<!-- 
  v-throttle:time='event', 事件在连续触发时，间隔一段时间执行一次
  time: 延迟事件毫秒数
  event：执行事件

 -->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> -->
  <script src="./vue.js"></script>
  <title >自定义指令实现防抖</title>
</head>

<body>
  <div id="app">
    <button  v-throttle="submit" >提交按钮</button>
  </div>
  <script>
    var app = new Vue({
      el: '#app',
      directives:{
        'throttle':{
          bind:function(el,binding){
            el.addEventListener('click',(event)=>{
              if(!el.disable){
                el.disable = true
                setTimeout(() => {
                  el.disable = false
                  binding.value()
                }, binding.arg || 2000); 
              }
            })
          }
        }
      },
      methods: {
        submit(){
          console.log("提交表单")  
        }
      },
    })
  </script>
  <style>

  </style>
</body>
</html>